// webpack plugins
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.config.common.js');
var path = require("path");
var CompressionPlugin = require("compression-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var webpack = require("webpack");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');


/**
 * config
 * Reference: http://webpack.github.io/docs/configuration.html
 */
module.exports = webpackMerge(commonConfig, {
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'string-replace-loader',
        options: {
          search: '\\"\\/static/',
          replace: '"static',
          flags: 'ig'
        },
        enforce: "post"
      },
    ]
  },
  devtool: 'cheap-module-source-map',
  devServer: {
    inline: true,
    hot: true,
    historyApiFallback: true
  },
  output: {
    path: path.resolve(__dirname),
    publicPath: '',
    filename: '[name].js',
    chunkFilename: '[id].chunk.js'
  },
  target: 'electron-renderer',
  plugins: [
    new ExtractTextPlugin('styles/[name].css'),
    new CopyWebpackPlugin([{
      from: 'src/read-article.html',
      to: ''
    }, {
      from: 'src/client.html',
      to: ''
    }]),
    new webpack.DefinePlugin({
      BUILD_IN_PRODUCTION: JSON.stringify(true)
    }),
    new UglifyJSPlugin({
      comments: false,
      compress: {
        warnings: false,
        drop_debugger: true,
        drop_console: true
      }
    })
  ]
});